package com.dongfg.zcmserver.config;

import com.dongfg.zcmserver.exception.BaseException;
import io.ous.jtoml.JToml;
import io.ous.jtoml.Toml;

import java.io.IOException;

/**
 * System Config.
 * Created by 13071472 on 2015/11/2.
 */
public class Config {

    // Constants read from config file.

    public static String adminName;

    public static String adminPwd;

    public static String connectString;

    public static int sessionTimeout;

    // System constants

    public static final String DIGEST_SCHEME = "digest";

    // api version
    public static final String API_VERSION_V1 = "v1";

    static {
        try {
            Toml toml = JToml.parse(Config.class.getClassLoader().getResourceAsStream("config.toml"));
            adminName = toml.getString("admin.name");
            adminPwd = toml.getString("admin.password");
            connectString = toml.getString("server.connectString");
            sessionTimeout = toml.getLong("server.sessionTimeout").intValue();
        } catch (IOException e) {
            throw new BaseException(Message.configError);
        }
    }

}
